#include <stdio.h>

#define SIZE 300

int prime(int n)
{
	int i;
	for (i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
			return 0;
	}
	return 1;
}


int main()
{
	int n;
	scanf("%d", &n);
	int i = 0, j = 0;
	int flag = 1;
	int a[SIZE] = { 0 };
	
	for (i = 2, j = 0; i <= n; i++)
	{
		if (prime(i))
		{
			a[j] = i;
			j++;
		}
	}
	int len = j;
	int tmp = -100;
	for (i = 1; i < len; i++)
	{
		tmp = tmp > (a[i] - a[i - 1]) ? 
			tmp : (a[i] - a[i - 1]);
	}
	printf("%d\n", tmp);
	return 0;
}